<template>
    <div class="company-set" style="padding: 15px">
        <!-- 基础语录 quot -->
        <div style="margin: 5px 0">
            <span>下单时间:</span>
            <div class="inline-block">
                <el-date-picker
                    v-model="searchParam.begintime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    size="mini"
                    placeholder="选择日期时间"
                >
                </el-date-picker>
            </div>
            <span>至:</span>
            <div class="inline-block">
                <el-date-picker
                    v-model="searchParam.endtime"
                    type="datetime"
                    size="mini"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期时间"
                >
                </el-date-picker>
            </div>
            <el-button type="primary" size="mini" @click="reSearch"
                >检索</el-button
            >
        </div>
        <el-table
            :data="orderList"
            border
            size="mini"
            :header-cell-style="headerCellStyle"
            style="width: 100%"
        >
            <el-table-column prop="payNo" label="支付订单号" align="center">
            </el-table-column>
            <el-table-column
                prop="payTradeNo"
                label="第三方支付单号"
                min-width="100"
            ></el-table-column>
            <el-table-column
                prop="companyName"
                label="关联业务类型"
                align="center"
            >
                <template slot-scope="scope">
                    <span v-show="scope.row.bussType === 1">增值服务应用</span>
                </template>
            </el-table-column>
            <el-table-column prop="bussNo" label="关联业务单号" align="center">
            </el-table-column>
            <el-table-column prop="totalFee" label="金额" align="center">
                <template slot-scope="scope">
                    <span>{{ $fix2(scope.row.totalFee / 100) }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="createTime" label="下单时间" align="center">
                <template slot-scope="scope">
                    <span>{{ $dateFormat2(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="payStatus" label="状态" align="center">
                <template slot-scope="scope">
                    <!-- 状态 1- 未成功 2-成功 -->
                    <span v-show="scope.row.payStatus === 1">未成功</span>
                    <span v-show="scope.row.payStatus === 2">成功</span>
                </template>
            </el-table-column>
        </el-table>
        <div class="text-c pt10" v-show="pageTotal > pageSize">
            <el-pagination
                @size-change="pageChange"
                @current-change="pageChange"
                :current-page.sync="currentPage"
                :page-size="pageSize"
                layout="prev, pager, next, jumper"
                :total="pageTotal"
            >
            </el-pagination>
        </div>
    </div>
</template>

<script >
import vueQr from 'vue-qr'
export default {
    components: {
        vueQr
    },
    // 0 正常 1 异常 2 黑名单
    data: function () {
        return {
            searchParam: {
                begintime: '',
                endtime: '',
                buyName: ''
            },
            stateSelect: '',
            stateSelectIndex: 0,
            page: 1,
            orderList: [],
            currentPage: 0,
            pageSize: 10,
            pageTotal: 0,
            dialog: false,
            qrSize: 160,
            qrMargin: 10,
            qrLogoSrc: '/addService/static/pic/weChat.png',
            qrLogoScale: 30,
            queryorderTimer: null
        }
    },
    computed: {
    },
    watch: {
    },
    created () {
        this.searchParam.begintime = this.dateToStr(new Date()) + ' 00:00:00'
        this.searchParam.endtime = this.dateToStr(new Date()) + ' 23:59:59'
        this.reSearch()
    },
    methods: {
        reSearch () {
            // 点击搜索
            this.currentPage = 1
            this.queryorderlist()
        },
        queryorderlist () {
            if (!this.searchParam.begintime) {
                return this.$message({
                    message: '开始时间不能为空',
                    type: 'warning'
                })
            }
            if (!this.searchParam.endtime) {
                return this.$message({
                    message: '结束时间不能为空',
                    type: 'warning'
                })
            }
            if (this.searchParam.endtime < this.searchParam.begintime) {
                return this.$message({
                    message: '开始时间不能大于结束时间',
                    type: 'warning'
                })
            }
            // 商家应用商城订单查询
            this.$axios({
                url: this.$store.state.ip + '/pay/addspay/companypayorderlist',
                data: {
                    data: {
                        begintime: new Date(Date.parse(this.searchParam.begintime.replace(/-/g, '/'))).getTime(),
                        endtime: new Date(Date.parse(this.searchParam.endtime.replace(/-/g, '/'))).getTime(),
                        companyCode: this.$store.state.loginParams.agentId ? '' : this.$store.state.loginParams.companyCode,
                        agentId: this.$store.state.loginParams.agentId,
                        page: this.currentPage - 1,
                        limit: this.pageSize
                    }
                },
                method: 'POST'
            }).then(res => {
                res = res.data
                this.orderList = []
                if (res.ret === '0') {
                    this.orderList = res.data.list
                    this.pageTotal = res.data.total
                } else {
                    this.pageTotal = 0
                    this.$message({
                        message: res.msg || '获取订单失败',
                        type: 'warning'
                    })
                }
            }).catch(err => {
                console.log(err)
            })
        },
        toInvoice (orderNo, orderContent, totalMoney) {
            console.log('aaaa')
            this.$router.push({ path: '/mainPage/invoice', query: { orderNo: orderNo, orderContent: orderContent, totalMoney: totalMoney } })
        },
        toInvoiceInfo (orderNo) {
            this.$router.push({ path: '/mainPage/invoiceInfo', query: { orderNo: orderNo } })
        },
        begintimeChange (value) {
            // 开始时间 选择
            this.searchParam.begintime = value
        },
        endtimeChange (value) {
            // 选择结束时间
            this.searchParam.endtime = value
        },
        pageChange (page) {
            // 页码 变化
            this.currentPage = page
            this.queryorderlist()
        },
        stateSelectChange (value) {
            // 状态选择
            this.stateSelectIndex = value
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.title
    display: inline-block
    min-width: 120px
    text-align: right
    font-weight: bold

.value
    display: inline-block
    min-width: 150px
</style>
